package net.hn.hnms.biz.safety.wind.Service;

import net.hn.hnms.biz.safety.wind.Dao.WindDoorDao;
import net.hn.hnms.biz.safety.wind.Dao.WindDoorDetailsDao;
import net.hn.hnms.biz.safety.wind.entity.WindDoorDetailsEntity;
import net.hn.hnms.biz.safety.wind.entity.WindDoorDetailsVO;
import net.hn.hnms.biz.safety.wind.entity.WindDoorEntity;
import net.hn.hnms.biz.safety.wind.entity.WindDoorVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 智呈物联 nzw
 * @date 2022/12/22
 */

@Service
public class WindDoorService {

    private WindDoorDao windDoorDao;

    private WindDoorDetailsDao windDoorDetailsDao;

    private PositionService positionService;

    @Autowired
    public void setWindDoorDao(WindDoorDao windDoorDao) {
        this.windDoorDao = windDoorDao;
    }

    @Autowired
    public void setWindDoorDetailsDao(WindDoorDetailsDao windDoorDetailsDao) {
        this.windDoorDetailsDao = windDoorDetailsDao;
    }

    @Autowired
    public void setPositionService(PositionService positionService) {
        this.positionService = positionService;
    }

    public List<WindDoorVO> findWindDoor(String mineCode){
        List<WindDoorVO> list = new ArrayList<>();
        List<WindDoorEntity> windDoorEntityList = windDoorDao.findAllByMineCode(mineCode);
        for (WindDoorEntity windDoorEntity : windDoorEntityList){
            WindDoorVO windDoorVO = new WindDoorVO();
            windDoorVO.setPositionName(positionService.getPositionName(windDoorEntity.getPositionId()));
            windDoorVO.setVideoChannelId(windDoorEntity.getVideoChannelId());

            List<WindDoorDetailsVO> windDoorDetailsVOList = new ArrayList<>();

            List<WindDoorDetailsEntity> windDoorDetailsEntityList = windDoorDetailsDao.findByWindDoorId(windDoorEntity.getId());
            for (WindDoorDetailsEntity windDoorDetailsEntity:windDoorDetailsEntityList){
                WindDoorDetailsVO windDoorDetailsVO = new WindDoorDetailsVO();
                windDoorDetailsVO.setCloseInPlace(windDoorDetailsEntity.getCloseInPlace());
                windDoorDetailsVO.setOpenInPlace(windDoorDetailsEntity.getOpenInPlace());
                windDoorDetailsVOList.add(windDoorDetailsVO);
            }
            windDoorVO.setList(windDoorDetailsVOList);
            list.add(windDoorVO);
        }
        return list;
    }
}
